// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <pollux/functions/prestosql/json/simd_json_util.h>

#include <pollux/common/base/pollux_exception.h>

namespace kumo::pollux {
    void simdjsonErrorsToExceptions(
        std::exception_ptr exceptions[simdjson::NUM_ERROR_CODES]) {
        for (int i = 1; i < simdjson::NUM_ERROR_CODES; ++i) {
            simdjson::simdjson_error e(static_cast<simdjson::error_code>(i));
            exceptions[i] = toPolluxException(std::make_exception_ptr(e));
        }
    }

    simdjson::simdjson_result<simdjson::ondemand::document> simdjsonParse(
        const simdjson::padded_string_view &json) {
        thread_local simdjson::ondemand::parser parser;
        return parser.iterate(json);
    }

    simdjson::padded_string_view reusePaddedStringView(
        const std::string_view &json) {
        return simdjson::padded_string_view(
            json.data(), json.length(), json.length() + simdjson::SIMDJSON_PADDING);
    };
} // namespace kumo::pollux
